﻿using System;
using System.Collections.Generic;
using System.Text;
using Lswweb.Model;
using Lswweb.Domain;

namespace Lswweb.Controls
{
    public class NewsList : SkinnedGridView<NewsInfo>
    {
        protected override IList<NewsInfo> GridViewDataSourceHandler(int pageIndex, int pageSize, out int totalRecord)
        {
            int currentCategoryId = CategoryId > 0 ? CategoryId : BaseNodeId;

            return News.GetNewsList(SearchKey, SearchType, currentCategoryId, Status, AuditingStatusType.Approved, IsHot, IsTop, MaxDateTime, MinDateTime, pageIndex, pageSize, out totalRecord);
        }

        private string searchKey = SiteContext.Current.SearchKey;
        /// <summary>
        /// 默认值从Url中读取参数SearchKey
        /// </summary>
        public string SearchKey
        {
            get
            {
                return searchKey;
            }
            set
            {
                searchKey = value;
            }
        }

        private SearchKeyType searchType = (SearchKeyType)(-1);
        /// <summary>
        /// 搜索类型，默认值为Url参数SearchType，如无Url参数SearchType则为NewsSearchKeyType.LoginName
        /// </summary>
        public SearchKeyType SearchType
        {
            get
            {
                if (Enum.IsDefined(typeof(SearchKeyType), searchKey))
                    return searchType;
                else if (Enum.IsDefined(typeof(SearchKeyType), SiteContext.Current.SearchType))
                    return (SearchKeyType)SiteContext.Current.SearchType;
                else
                    return SearchKeyType.Title;
            }
            set
            {
                searchType = value;
            }
        }

        private StatusType status = (StatusType)(-1);
        public StatusType Status
        {
            get
            {
                if (Enum.IsDefined(typeof(StatusType), status))
                    return status;
                else
                    return (StatusType)SiteContext.Current.Status;
            }
            set
            {
                status = value;
            }
        }

        private BooleanType iscommend = BooleanType.None;
        public BooleanType IsHot
        {
            get { return iscommend; }
            set { iscommend = value; }
        }

        private BooleanType istop = BooleanType.None;
        public BooleanType IsTop
        {
            get { return istop; }
            set { istop = value; }
        }

        private int categoryId = -1;
        public int CategoryId
        {
            get
            {
                if (categoryId == -1)
                    return SiteContext.Current.CategoryId;
                else
                    return categoryId;
            }
            set
            {
                categoryId = value;
            }
        }

        private int baseNodeId = -1;
        public int BaseNodeId
        {
            get { return baseNodeId == -1 ? SiteContext.Current.BaseNodeId : baseNodeId; }
            set { baseNodeId = value; }
        }

        private DateTime maxDateTime = DateTime.MinValue;
        public DateTime MaxDateTime
        {
            get
            {
                if (maxDateTime == DateTime.MinValue)
                    return SiteContext.Current.MaxDateTime;
                else
                    return maxDateTime;
            }
            set
            {
                maxDateTime = value;
            }
        }

        private DateTime minDateTime = DateTime.MinValue;
        public DateTime MinDateTime
        {
            get
            {
                if (minDateTime == DateTime.MinValue)
                    return SiteContext.Current.MinDateTime;
                else
                    return minDateTime;
            }
            set
            {
                minDateTime = value;
            }
        }

        /// <summary>
        /// 配置为Resource.xml中的name值
        /// </summary>
        public string IconStr { get; set; }

        private bool enableDelButton = true;
        public bool EnableDelBtn
        {
            get 
            {
                if (SiteContext.Current.EnableDelButton != enableDelButton)
                    enableDelButton = SiteContext.Current.EnableDelButton;

                return enableDelButton;
            }
            set { enableDelButton = value; }
        }

        private bool enableTopButton = true;
        public bool EnableTopBtn
        {
            get
            {
                if (SiteContext.Current.EnableTopButton != enableTopButton)
                    enableTopButton = SiteContext.Current.EnableTopButton;

                return enableTopButton;
            }
            set { enableTopButton = value; }
        }

        private bool enableHotButton = true;
        public bool EnableHotBtn
        {
            get
            {
                if (SiteContext.Current.EnableHotButton != enableHotButton)
                    enableHotButton = SiteContext.Current.EnableHotButton;

                return enableHotButton;
            }
            set { enableHotButton = value; }
        }

        protected override string DefaultSkinFilename
        {
            get { return "News/NewsList.ascx"; }
        }
    }
}
